<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增交货路线')" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-role-add">
        <div class="form-group">
            <label class="col-sm-3 control-label ">工艺路线标识：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="routeId" id="routeId" required >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">描述：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="description" id="description" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">运转公司标识：</label>
            <div class="col-sm-8">
                <input id="forwardAgentId" name="forwardAgentId" class="form-control" type="text">
            </div>
        </div>
       <!-- <div class="form-group">
            <label class="col-sm-3 control-label">在航层检查：</label>
            <div class="col-sm-8">
                是：
                <input type="radio" checked="checked" name="checkOnLineLevel" value="TRUE">
                否：
                <input type="radio" name="checkOnLineLevel" value="FALSE">
            </div>
        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">在航层检查：</label>
            <div class="col-sm-8">
                <label class="toggle-switch switch-solid">
                    <input type="checkbox" id="checkOnLineLevel" checked>
                    <span></span>
                </label>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: ztree-js" />
<script type="text/javascript">
    $("#form-role-add").validate({
        rules:{
            onkeyup: false,
            routeId:{
                remote: {
                    url: ctx + "goodsPath/checkRouteId",
                    type: "post",
                    dataType: "json",
                    data: {
                        "routeId" : function() {
                            return $.common.trim($("#routeId").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
        },
        messages: {
            "routeId": {
                remote: "工艺路线标识已经存在"
            }
        },
        focusCleanup: true
    });
    function submitHandler() {
        if ($.validate.form()) {
            add();
        }
    }

    function add() {
        var routeId = $("input[name='routeId']").val();
        var description = $("input[name='description']").val();
        var forwardAgentId = $("input[name='forwardAgentId']").val();
//        var checkOnLineLevel = $("input[name='checkOnLineLevel']").val();
        var checkOnLineLevel = $("input[id='checkOnLineLevel']").is(':checked') == true ? 'TRUE': 'FALSE';
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "goodsPath/add",
            data : {
                "routeId": routeId,
                "description": description,
                "forwardAgentId": forwardAgentId,
                "checkOnLineLevel": checkOnLineLevel
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.successCallback(data);
            }
        });
    }
</script>
</body>
</html>
